(* Crible d'Eratosthène *)

let n : int ref = ref (-1) in
let b : bool array = Array.make 100 true in
let creer_tab( t : bool array ) =
  t.(1) <- false
in
let cribler( p : int ) =
  let m : int ref = ref (-1) in
  begin
    m := 2 * p;
    while !m <= !n do
 
      b.(!m) <- false;
      m := !m + p
    done
  end
in
let afficher_tab( ) =
  let p : int ref = ref 1 in
  begin
    while !p <= !n do
      if b.(!p) then
        begin
          print_int( !p );
          print_string " "
        end;
      p := !p + 1
    done
  end
in
let crible_eratosthene( ) =
   let p : int ref = ref 2 in 
   begin
     creer_tab( b );
     while !p <= !n do
       if b.(!p) then
         begin
           cribler( !p )
         end;
       p := !p + 1
     done;
   afficher_tab( )
   end
in
begin
  print_string "Jusqu'où voulez-vous aller ? (tapez un nombre entre 2 et 100)\n";
  n := read_int();
  crible_eratosthene() 
end
;;
 
